﻿@{
    ViewBag.Title = "MNPackage";
    Layout = "~/Views/Shared/_CpanelLayout.cshtml";
    var id = (int)ViewBag.ID;

}

<link rel="stylesheet" href="@Url.Content("~/Content/jqwidgets/styles/jqx.base.css")" type="text/css" />
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcore.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdata.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxbuttons.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxscrollbar.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxmenu.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcheckbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxlistbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdropdownlist.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.sort.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.pager.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.selection.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.edit.js")"></script> 
<script type="text/javascript">
    $(document).ready(function () {

        var url = "@Url.Action("GetJsonPackage","Product",new {id=@id})";
        
            var source =
            {
                datatype: "json",
                datafields: [
                    { name: 'ID', type: 'int' },
                    { name: 'DisplayName', type: 'string' },
                    { name: 'DisplayNamePackage', type: 'string' },
                ],
                id: 'ID',
                url: url
            };
            var dataAdapter = new $.jqx.dataAdapter(source, {
                downloadComplete: function (data, status, xhr) { },
                loadComplete: function (data) { },
                loadError: function (xhr, status, error) { }
            });
            // initialize jqxGrid
            $("#jqxgrid").jqxGrid(
            {
                width: 940,
                source: dataAdapter,
                pageable: true,
                autoheight: true,
                sortable: true,
                altrows: true,
                enabletooltips: true,
                editable: true,
                selectionmode: 'multiplecellsadvanced',
                columns: [
                  { text: 'ID ', datafield: 'ID', width: 150 },
                  { text: 'Tên Gói ', datafield: 'DisplayNamePackage', width: 240 },
                  { text: 'Tên sản phẩm ', datafield: 'DisplayName', width: 240 },
                  {
                      text: 'Quản lí', datafield: 'Quản lí', columntype: 'button', width: 120, cellsrenderer: function () {
                          return "Quản lí";
                        }, buttonclick: function (editrow) {

                            var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                            window.location = "@Url.Action("MNPackageBenefit","Product")/" + dataRecord.ID;
                      }
                  },
                  {
                      text: 'Chỉnh sửa', datafield: 'Edit', columntype: 'button', width: 100, cellsrenderer: function () {
                          return "Edit";
                      }, buttonclick: function (editrow) {

                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                          window.location = "@Url.Action("EditPackageProduct","Product")/" + dataRecord.ID;
                     }
                  },
                  {
                      text: 'Xóa', datafield: 'Xóa', columntype: 'button', width: 100, cellsrenderer: function () {
                          return "Xóa";
                      }, buttonclick: function (editrow) {

                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                          var rr = confirm("Bạn có muốn xóa gói bảo hiểm của sản phẩm \"" + dataRecord.DisplayName + "\" ?");
                          if (rr) {
                              $.ajax({
                                  type: "post",
                                  url: "@Url.Action("DeletePackageProduct","Product")",
                                  data: { ID: dataRecord.ID },
                                  datatype: "json",
                                  success: function (rvdata) {
                                      if (rvdata == "Success") {
                                          $("#jqxgrid").jqxGrid({ source: dataAdapter });
                                      }
                                  }

                              });
                          }//end rr

                      }
                  }
                ]
            });
        });
    </script>
<div class="container" style="padding:10px;">
    <fieldset>
                 <legend >Quản lý Gói bảo hiểm sản phẩm</legend>
   </fieldset>
    <br />
     @Html.ActionLink("Thêm gói quyền lợi cho sản phẩm","AddPackageProduct", "Product",new { id=@id},null)<br />
   
    <br />
   <div id="jqxgrid" class="container">

   </div>
</div>

